<%@page import="java.util.*" import="java.sql.ResultSet" import="java.sql.Statement" import="java.sql.Connection" import="connection.DBConnection" language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@page import="java.text.SimpleDateFormat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Journal Voucher</title>
<script language="javascript" type="text/javascript">

function checkDate()
{
	var c1;
	
  	var datevalid=/^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
  		
        c1= document.f14.rdate.value;

        if(c1.length==0)
        {
        	alert("Enter Date");
            return false;
      	 }
        if(!c1.match(datevalid))
        {
            alert("Please Enter Date in DD/MM/YYYY Format");
            document.f14.rdate.value="";
            document.f14.rdate.focus();
            
	         return false;
    	 }
        else
        {
        	dateval=c1.match(datevalid);
        }
        
        var dtYear = dateval[1];        
        dtMonth = dateval[3];
        dtDay=  dateval[5];

     if (dtMonth < 1 || dtMonth > 12) 
        return false;
     else if (dtDay < 1 || dtDay> 31) 
       return false;
     else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31) 
       return false;
     else if (dtMonth == 2){ 
       var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
       if (dtDay> 29 || (dtDay ==29 && !isleap)) 
      	 
      	 alert("Date format is not correct");
       document.f14.rdate.value="";
       document.f14.rdate.focus();
              return false;
        
        return true;
}
     
</script>
</head>
<body>
<form name="f15" action="EditJournalVoucherServlet" ONSUBMIT="return checkDate()">

<% 		String selectedaccnumber = (String) request.getAttribute("vnumber");


		DBConnection dbc=new DBConnection();	
		Connection con=dbc.getNewConnection();

		Statement st = null;
		ResultSet rs = null;
		String code2="";
		
		String j1="",j2="",j3="",j5="",j7="",j8="",j9="",j10="",j11="";
		double j4=0.0,j6=0.0;
		
	
		try
		{
			st=con.createStatement() ;
			rs=st.executeQuery("select * from JournalVoucher2 where jname='"+selectedaccnumber+"' "); %>
  
			<%  while(rs.next()) 
				{ 
					j1=rs.getString(1);
					j2=rs.getString(2);
					j3=rs.getString(3);
					j4=rs.getDouble(4);
					j5=rs.getString(5);
					j6=rs.getDouble(6);
					j7=rs.getString(7);
					j8=rs.getString(8);
					j9=rs.getString(9);
					j10=rs.getString(10);
					j11=rs.getString(11);
				}  
		 }
		catch(Exception e){} 		
%>

<table border=0>

<tr>
	<td> Voucher Entry Number </td>
	
<%--			<%	
				DBConnection dbc=new DBConnection();	
				Connection con=dbc.getNewConnection();
		
			 	Statement st = null;
			 	ResultSet rs = null;
			 	String code2="";
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select MAX(jname) from JournalVoucher2"); %>
       		   
       		 <%  while(rs.next()) 
       		 	{ 
       				String code1=rs.getString(1);
       				
       			    String[] part = code1.split("(?<=\\D)(?=\\d)");
	   		       
	   		       String p0=part[0];		       
	   		       int p1=Integer.parseInt(part[1]);
	   		      
	   		       p1++;
	   		       
	   		       code2=p0+""+p1;

            	} %>
  
	 		<% }
		   catch(Exception e){} %>
--%>
	<td> <input type="text" name="jentrynumber" value="<%=j1 %>"> </td>
</tr>

	<% 	
	     SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
		 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
		 String v2 =formatter.format(fromsql.parse(j2));

	%>

<tr>
	<td> date </td>	
	<td><input type="text" name="jdate" value="<%=v2 %>" /></td>
</tr>

<tr>
	<td> Account Debited </td>
	<td> <input type=text name=jaccount value="<%=j3 %>"> </td>
	
<%--			 <%	
			 try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select ccode,cname from CustomerMaster"); %>
	<td> 
	  <select name="jaccount" id="jaccount" >
	  		<option> </option>
       		 <%  while(rs.next()){ %>
            		<option value="<%=rs.getString(1) %>" > <%=rs.getString(2)%> </option>
            		            		
        	<% } %>
  				
	 <% }
		catch(Exception e){} %>
	
		
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select scode,sname from SupplierMaster"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		 
        	<% } %>
 
	 <% }
		catch(Exception e){} %>
	
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select gcode,gname from GeneralLedger2"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		   
        	<% } %>
        </select>	
	</td>
	 <% }
		catch(Exception e){} %>
--%>
</tr>

<tr>
	<td colspan=2> Create New Account  </td>
</tr>
<tr>	
	<td colspan=2> <input type="radio" name="r1"> <a href="CustomerMaster.jsp"> Customer </a>
		 <input type="radio" name="r1"> <a href="SupplierMaster.jsp"> Supplier </a> 
		 <input type="radio" name="r1"> <a href="GeneralLedger.jsp"> GeneralLedger </a>
	</td>
</tr>

<tr>
	<td> Amount </td>
	<td> <input type="text" name="jamount" value="<%=j4 %>"> </td>
</tr>

<tr>
	<td> Account Credited </td>
	<td> <input type="text" name="jaccount2" value="<%=j5 %>"> </td> 
				<!--  jaccount2 --> 
	
<%--			 <%	
			 try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select ccode,cname from CustomerMaster"); %>
	<td> 
	  <select name="jaccount2" id="jaccount2" >
	  		<option> </option>
       		 <%  while(rs.next()){ %>
            		<option value="<%=rs.getString(1) %>" > <%=rs.getString(2)%> </option>
            		            		
        	<% } %>
  				
	 <% }
		catch(Exception e){} %>
	
		
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select scode,sname from SupplierMaster"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		 
        	<% } %>
 
	 <% }
		catch(Exception e){} %>
	
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select gcode,gname from GeneralLedger2"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		   
        	<% } %>
        </select>	
	</td>
	 <% }
		catch(Exception e){} %>
--%>
</tr>

<tr>
	<td colspan=2> Create New Account  </td>
</tr>

<tr>	
	<td colspan=2> <input type="radio" name="r1"> <a href="CustomerMaster.jsp"> Customer </a>
		 <input type="radio" name="r1"> <a href="SupplierMaster.jsp"> Supplier </a> 
		 <input type="radio" name="r1"> <a href="GeneralLedger.jsp"> GeneralLedger </a>
	</td>
</tr>

<tr>
	<td> Amount </td>
	<td> <input type="text" name="jamount2" value="<%=j6 %>"> </td>
</tr>

<tr>
	<td> Narration </td>
	<td> <input type="text" name="jnarration" value="<%=j7 %>"> </td>
</tr>

<tr>
	<td> <input type="submit" value="Submit" > </td>
</tr>

</table>
</form>


<form action="JournalVoucherDeleteServlet">
 <input type="submit" value="Delete">
 <input type=hidden name="delete" value="<%=j1 %>">
</form>


</body>
</html>